from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException,TimeoutException,\
     ElementClickInterceptedException,StaleElementReferenceException,\
     NoSuchWindowException
from selenium.webdriver.common.action_chains import ActionChains
import json,time,os,re
import requests,bs4
import sys
sys.path.append(r'C:\Users\Administrator\Desktop\python\习题\项目\publish_news')
from cookie_login import Cookie_login
from web_class import *
from easyExcel import EasyExcel
from mysql import MySql
from wechat import Wechat
from compress_img import CompressImage
log_url ={
    'baidu': ('https://baijiahao.baidu.com/','13601135657','CYTcyt0910'),#cookie登陆
    'yidianzixun': ('https://mp.yidianzixun.com/','13601135657','CYTcyt0910'),#密码错误，异地报错，需要手机验证
    'sina': ('http://mp.sina.com.cn/','13601135657','GBNgbn22222'),#建议用密码登录，登录后有弹窗
    'sohu': ('http://mp.sohu.com','346764791','GBNgbn22222'),#需要qq验证，可以cookie登陆
    '163': ('http://mp.163.com/','gbngbn@126.com','CYTcyt22222'),#标题字数在11-30
    
    'dayu': ('https://mp.dayu.com/','346764791@qq.com','GBNgbn22222'),#
    'ifeng': ('http://fhh.ifeng.com/login','346764791','GBNgbn22222'),#QQ，拷贝cookie时，取.ifeng.com的域名
    'youcheyihou': ('http://mp.youcheyihou.com','bangninggongzuoshi','GBNgbn22222'),
    'qutoutiao': ('https://mp.qutoutiao.net/','13601135657','GBNgbn22222'),
    'weibo': ('https://weibo.com/','13601135657','GBNgbn22222'),#建议用密码登录
    'toutiao': ('https://mp.toutiao.com/','13601135657',''),#手机验证，建议cookie登陆
    

    #登陆存在问题的
    'autohome': ('https://chejiahao.autohome.com.cn/','帮宁工作室','GBNgbn22222'),#cookie登陆，有验证，图片需要大与560*315，长宽均大于
    'maiche': ('http://media.maiche.com/','13601135657','GBNgbn22222'),
    # 'weixin': ('https://mp.weixin.qq.com/','','GBNgbn22222'),#微信验证，建议cookie登陆
}

publish_url = {
    'baidu': 'https://baijiahao.baidu.com/builder/rc/edit?type=news&app_id=1591384705840207',
    'weibo': 'https://card.weibo.com/article/v3/editor#/draft',
    'sina': 'http://mp.sina.com.cn/main/editor?vt=4#/SendArt/Edit',
    'sohu': 'https://mp.sohu.com/mpfe/v3/main/news/addarticle?contentStatus=1',
    '163': 'http://mp.163.com/article/postpage/W8567100657272114912?wemediaId=W8567100657272114912',
    'dayu': 'https://mp.dayu.com/dashboard/article/write?spm=a2s0i.db_contents.menu.3.67c73caarUGcXk',
    'ifeng': 'http://fhh.ifeng.com/publish/article',
    'youcheyihou': 'http://mp.youcheyihou.com/#/article-edit',
    'qutoutiao': 'https://mp.qutoutiao.net/publish-content/article',
    'toutiao': 'https://mp.toutiao.com/profile_v3/graphic/publish',
    'yidianzixun': 'https://mp.yidianzixun.com/#/Writing/articleEditor',
    'autohome': 'https://chejiahao.autohome.com.cn/My/AuthorArticles/add/0#pvareaid=2808351',
    #'weixin': '',
    'maiche': 'http://media.maiche.com/manage/fun/publish.html',

}
query_url={
    'baidu': 'https://baijiahao.baidu.com/builder/rc/content?type=&collection=&pageSize=10&currentPage=1&search=&app_id=1591384705840207',
    'weibo': 'https://weibo.com/5646432272/profile?rightmod=1&wvr=6&mod=personinfo&is_all=1',
    'sina': 'http://mp.sina.com.cn/#/ContentList',
    'sohu': 'https://mp.sohu.com/mpfe/v3/main/news/articlelist',
    '163': 'http://mp.163.com/index.html#/article/manage?wemediaId=W8567100657272114912',
    'dayu': 'https://mp.dayu.com/dashboard/contents',
    'ifeng': 'http://fhh.ifeng.com/manage/originalArticle',
    'youcheyihou': 'http://mp.youcheyihou.com/#/article-original',
    'qutoutiao': 'https://mp.qutoutiao.net/content-manage/article?status=&page=1&title=&submemberid=&nickname=&start_date=&end_date=&isMotherMember=false',
    'toutiao': 'https://mp.toutiao.com/profile_v3/graphic/articles',
    'yidianzixun': 'https://mp.yidianzixun.com/#/ArticleManual/original/publish',
    'autohome': 'https://chejiahao.autohome.com.cn/My/Info?r=564765768',
    #'weixin': '',
    'maiche': 'http://media.maiche.com/manage/fun/article.html',
}
map_from_name_to_class = {
    'baidu': Bjh,
    'weibo': Weibo,
    'sina': Sina,
    'sohu': Sohu,
    '163': W163,
    'dayu': Dayu,
    'ifeng': Ifeng,
    'youcheyihou': Youche,
    'qutoutiao': Qtt,
    'toutiao': Toutiao,
    'yidianzixun': Ydzx,
    'autohome': Cjh,
    'maiche': Cheyou,
}
map_zh_eng = {
    '百家号':'baidu',
    '网易号':'163',
    '新浪微博':'weibo',
    '新浪看点':'sina',
    '大风号':'ifeng',
    '大鱼号':'dayu',
    '趣头条':'qutoutiao',
    '搜狐号':'sohu',
    '有车号':'youcheyihou',
    '车友号':'maiche',
    '微信号':'weixin',
    '一点号':'yidianzixun',
    '头条号':'toutiao',
    '车家号': 'autohome',
    '企鹅号': 'qq',

}
map_eng_zh = dict(zip(map_zh_eng.values(),map_zh_eng.keys()))
class Cookie_login_1():
    def __init__(self,driver=None,path=None):
        chrome_options = Options()
        chrome_options.add_argument(r"user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data_1")
        if not path:
            download_path = r'C:\Users\Administrator\Desktop\test\credit_system\%s' %path
        else:
            download_path = r'C:\Users\Administrator\Desktop\test\credit_system'
        prefs = {'profile.default_content_setting_values' :{'notifications' : 2},\
            'download.default_directory': download_path,\
            'profile.default_content_settings.popups': 0}
        chrome_options.add_experimental_option('prefs',prefs)
        chrome_options.add_argument("window-size=1024,768")
        if not driver:
            self.driver = webdriver.Chrome(options=chrome_options, executable_path=\
                r'C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\Tools\chromedriver_win32\chromedriver.exe')
        else:
            self.driver = driver
def switch(name):
    global d
    d.switch_to.window(D[name])
    
C = Cookie_login()
d = C.driver
def open_one(name):

    #C.open_new_window(log_url[name][0])
    #C.load_cookie_by_name(name)
    #d.refresh()
    d.get(publish_url[name])


W = Web(d,'test',C.message)
            






